/**
 * Created by lee_mxue on 17/2/13.
 */
import React from "react";
import ReactDOM from "react-dom";
import { addErrorListener } from "../../lib/handleError"
import weixinShare from "../../lib/weixinShare"
import AJAX from "../../lib/ajax"

require('../../lib/rem');
require('./OrderInfo.less');
require('../../styles/common.less');
require('../../styles/resetWeui.less');
require('../../styles/lux.less')


class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            order_info: undefined
        };
    }
    componentWillMount() {
        addErrorListener()()
        weixinShare.hideAll();
    }

    componentDidMount() {
        AJAX.appendBaiduAnalysis()

        //获取签名
        // AJAX.request("get_signature", {
        //     full_url: window.location.href
        // }, (data) => {
        //获取localStorage－－－站点信息
        var order_info = JSON.parse(localStorage.getItem("order_info_x"))
        // alert(localStorage.getItem("order_info_x"))
        // alert(order_info.img_code)
        this.setState({
            order_info: order_info
        })
        // })
        //    清楚寄件页面localStorage
        window.localStorage.removeItem("logisInfo_x");  //寄件站点信息
        window.localStorage.removeItem("sender_addr_x");  //寄件人信息
        window.localStorage.removeItem("receiverData_x");  //收件人信息
        window.localStorage.removeItem("sendingPackageHeader_defaultExpress_x");  //默认快递公司
        window.localStorage.removeItem("sendingPackageHeader_goodName_x");  //已选物品名称
        window.localStorage.removeItem("sendingPackageHeader_goodWeight_x");  //已选物品重量
        window.localStorage.removeItem("sendingPackageHeader_expressInfo_x");  //已选快递公司
        window.localStorage.removeItem("sendingPackageHeader_payType_x");  //已选付款方式
        window.localStorage.removeItem("sendingPackageHeader_vipCode_x");  //已填写VIP卡号
        //    清楚查询快递页面localStorage
        window.localStorage.removeItem("checkPackage_express_info_x");  //已选快递公司信息
        window.localStorage.removeItem("PackageTracker_package_id_x");  //快递单号信息
    }


    render() {
        return (
            <div className="main">
                {this.state.order_info && <div className="flex top_active white">
                    <div>
                        <p className="textGray">{this.state.order_info.sender_addr.province}, {this.state.order_info.sender_addr.city}</p>
                        <p>{this.state.order_info.sender_addr.realname}</p>
                    </div>
                    <div>
                        >>
                    </div>
                    <div>
                        <p className="textGray">{this.state.order_info.consignee_addr.province}, {this.state.order_info.consignee_addr.city}</p>
                        <p>{this.state.order_info.consignee_addr.realname}</p>
                    </div>
                </div>}

                {this.state.order_info && <div className="flex_column center_content white">
                    <div className="content_top">
                        <p className="fontSize14px">
                            请前往近邻宝服务网点寄件,到店可打印快递单哟~
                        </p>
                        <div className=" weui-cells borderL borderR">
                            <div className="weui-cell weui-cell_access">
                                <div className="weui-cell__hd">
                                    <i className="iconfont textGray icon-dingwei"></i>
                                </div>
                                <div className="weui-cell__bd">
                                    <p className="fontSize16px">{this.state.order_info.logis_info.name}</p>
                                    <p className="fontSize12px textGray">{this.state.order_info.logis_info.address}</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div className="content_center ">
                        <p className="fontSize16px">快递一维码</p>
                        <p className="fontSize12px textGray">向服务网点展示一维码或者提供寄件手机号即可打印快递单~</p>
                        <img src={'data:image/jpeg;base64,'+this.state.order_info.img_code} alt="快递单"/>
                    </div>
                    <div className="content_bottom ">
                        <a href="./SendingPackageHeader" className="weui-btn  yellow fontSize16px">继续下单</a>
                        <a href="./MyPackage" className="weui-btn  white  fontSize16px">我的快递</a>
                    </div>

                </div>}
            </div>

        )
    }
}
ReactDOM.render(<App />, document.getElementById('app'));
if (module.hot) {
    module.hot.accept();
}